package it.clariter.web.action;

import it.clariter.dao.AreaDAO;
import it.clariter.dao.AziendaDAO;
import it.clariter.dao.ClienteDAO;
import it.clariter.dao.RuoloDAO;
import it.clariter.dao.TipologiaDocumentoDAO;
import it.clariter.dao.VersoDAO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class DefinisciAzioneAction extends DispatchAction {

	public ActionForward protocollo(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		TipologiaDocumentoDAO tipDao = new TipologiaDocumentoDAO();
		AreaDAO aDao = new AreaDAO();
		VersoDAO vDao = new VersoDAO();
		AziendaDAO aziendaDao = new AziendaDAO();
		ClienteDAO cDao = new ClienteDAO();
		HttpSession session = request.getSession();
		session.setAttribute("tipologie", tipDao.getList());
		session.setAttribute("aree", aDao.getList());
		session.setAttribute("versi", vDao.getList());
		session.setAttribute("aziende", aziendaDao.getList());
		session.setAttribute("clienti", cDao.getListTotale());
		return mapping.findForward("protocollo");
		
	}
	
	public ActionForward utente(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		RuoloDAO rDao = new RuoloDAO();
		HttpSession session = request.getSession();
		session.setAttribute("ruoli", rDao.getList());
		return mapping.findForward("utente");
		
		
	}
	
	public ActionForward cliente(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Clienti");
		session.setAttribute("valueCrud", "cliente");
		return mapping.findForward("cliente");
		
	}
	
	public ActionForward fornitore(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Fornitori");
		session.setAttribute("valueCrud", "fornitore");
		return mapping.findForward("fornitore");
		
	}
	
	public ActionForward azienda(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Aziende");
		session.setAttribute("valueCrud", "azienda");
		return mapping.findForward("azienda");
		
	}
	
	public ActionForward verso(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Verso");
		session.setAttribute("valueCrud", "verso");
		return mapping.findForward("verso");
		
	}
	
	public ActionForward area(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Aree");
		session.setAttribute("valueCrud", "area");
		return mapping.findForward("area");
		
	}
	
	public ActionForward tipologia(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("titolo", "Tipologie Documenti");
		session.setAttribute("valueCrud", "tipologia");
		return mapping.findForward("tipologia");
		
	}

}
